import { createRouter, createWebHistory } from 'vue-router'
import AdminLayout from '../layout/AdminLayout.vue'
import AdminDashboard from '../views/admin/Dashboard.vue'
import Login from '../views/Login.vue'
import RoleMaintenance from '../views/admin/system/permission/Role.vue'
import PermissionMaintenance from '../views/admin/system/permission/Permission.vue'
import UserList from '../views/admin/system/user/List.vue'
import UserAuth from '../views/admin/system/user/Auth.vue'
import ProjectList from '../views/admin/business/project/List.vue'
import ProjectAdd from '../views/admin/business/project/Add.vue'
import ProjectEdit from '../views/admin/business/project/Edit.vue'
import ProjectAudit from '../views/admin/business/project/Audit.vue'
import SupportRecords from '../views/admin/business/crowdfunding/Support.vue'
import RefundProcessing from '../views/admin/business/crowdfunding/Refund.vue'
import CategoryManagement from '../views/admin/business/content/Category.vue'
import ProjectStatistics from '../views/admin/statistics/Project.vue'
import UserStatistics from '../views/admin/statistics/User.vue'
import FundingStatistics from '../views/admin/statistics/Funding.vue'
import BasicConfiguration from '../views/admin/configuration/Basic.vue'
import OssConfiguration from '../views/admin/configuration/Oss.vue'
import SmsConfiguration from '../views/admin/configuration/Sms.vue'
import UpLoad from '@/views/UpLoad.vue'
const routes = [
  {
    path: '/login',
    name: 'Login',
    component: Login
  },
    {
    path: '/upload',
    name: 'upload',
    component: Login
  },
  {
    path: '/admin',
    component: AdminLayout,
    meta: { requiresAuth: true },
    children: [
      {
        path: 'dashboard',
        name: 'AdminDashboard',
        component: AdminDashboard
      },
      {
        path: 'system/permission/role',
        name: 'RoleMaintenance',
        component: RoleMaintenance
      },
      {
        path: 'system/permission/permission',
        name: 'PermissionMaintenance',
        component: PermissionMaintenance
      },
      {
        path: 'system/user/list',
        name: 'UserList',
        component: UserList
      },
      {
        path: 'system/user/auth',
        name: 'UserAuth',
        component: UserAuth
      },
      {
        path: 'business',
        children: [
          {
            path: 'project/list',
            name: 'AdminProjectList',
            component: () => import('@/views/admin/business/project/List.vue')
          },
          {
            path: 'crowdfunding/support',
            name: 'AdminSupport',
            component: () => import('@/views/admin/business/crowdfunding/Support.vue')
          },
          {
            path: 'crowdfunding/refund',
            name: 'AdminRefund',
            component: () => import('@/views/admin/business/crowdfunding/Refund.vue')
          },
          {
            path: 'content/category',
            name: 'AdminCategory',
            component: () => import('@/views/admin/business/content/Category.vue')
          }
        ]
      },
      {
        path: 'statistics/project',
        name: 'ProjectStatistics',
        component: ProjectStatistics
      },
      {
        path: 'statistics/user',
        name: 'UserStatistics',
        component: UserStatistics
      },
      {
        path: 'statistics/funding',
        name: 'FundingStatistics',
        component: FundingStatistics
      },
      {
        path: 'configuration/basic',
        name: 'BasicConfiguration',
        component: BasicConfiguration
      },
      {
        path: 'configuration/oss',
        name: 'OssConfiguration',
        component: OssConfiguration
      },
      {
        path: 'configuration/sms',
        name: 'SmsConfiguration',
        component: SmsConfiguration
      }
    ]
  },
  {
    path: '/',
    redirect: '/admin/dashboard'
  },
  {
    path: '/about',
    name: 'about',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
  }
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

// // 路由守卫
// router.beforeEach((to, from, next) => {
//   const isLoggedIn = localStorage.getItem('isLoggedIn') === 'true'
  
//   if (to.meta.requiresAuth && !isLoggedIn) {
//     next('/login')
//   } else if (to.path === '/login' && isLoggedIn) {
//     next('/admin/dashboard')
//   } else {
//     next()
//   }
// })

export default router
